
/**
 * 获取object类型消息
 * @returns json格式消息
 */
export function get_client_id() {
    return _global_.get_client_id();
}
/**
 * 获取object类型消息
 * @returns json格式消息
 */
export function get_client_message_json() {
    return JSON.parse(_global_.get_data());
}

/**
 * 获取字符类型消息
 * @returns 符类型消息
 */
export function get_client_message_string() {
    return _global_.get_data();
}

/**
 * 向指定客户端发送消息
 * @param message_type 消息序号
 * @param message_data 内容
 * @returns 符类型消息
 */
export function send_client_message(client_id, message_type, message_data) {
    _global_.send_client_message(client_id, JSON.stringify({
        "message_type": message_type,
        "message_data": message_data
    }));
}

/**
 * 向所有客户端发送消息
 * @param message_type 消息序号
 * @param message_data 内容
 * @returns 符类型消息
 */
export function send_all_client_message(message_type, message_data) {
    _global_.send_all_client_message(JSON.stringify({
        "message_type": message_type,
        "message_data": message_data
    }));
}

/**
 * 向角色客户端发送消息
 * @param {*} characters_id
 * @param {*} message_type 
 * @param {*} message_data 
 */
export function send_characters_client_message(characters_id, message_type, message_data) {
    let client_id = G.Characters.get_characters_client_id(characters_id);
    if (client_id !== undefined) {
        _global_.send_client_message(client_id, JSON.stringify({
            "message_type": message_type,
            "message_data": message_data
        }));
    }
}

/**
 * 向客户端发送常规提示
 * @param client_id 客户端id 
 * @param text 消息 
 */
export function send_basic_prompt(client_id, data) {
    send_client_message(client_id, 7, data);
}

/**
 * 向角色客户端发送常规提示
 * @param client_id 角色id 
 * @param text 消息 
 */
export function send_characters_basic_prompt(characters_id, data) {
    send_characters_client_message(characters_id, 7, data);
}


/**
 * 向客户端发送商店购买列表
 * @param client_id 角色id 
 * @param store_number 商店编号 
 */
export function send_characters_shoping_list(characters_id, store_number) {
    let characters = _CharactersData.get(characters_id);
    let shop_data = G.ShopStoreData.default[store_number];
    let type = G.ShopStoreData.ShopStoreEnum[shop_data[1]];
    let data = { "数据": shop_data, "编号": store_number, "余额": characters[type] };
    _CharactersOpoenStoreCache.set(characters_id, store_number);
    send_characters_client_message(characters_id, 9, data);
}


/**
 * 发送最后对话框
 * @param {*} name 
 * @param {*} model 
 * @param {*} text 
 * @param {*} select 
 */
export function send_client_dialogue(client_id, model, name, text, select, next_page, plot, flag_data) {
    if (flag_data) {
        _ClientDialogueDataFlag.set(client_id, flag_data);
    } else {
        _ClientDialogueDataFlag.delete(client_id);
    }
    _global_.send_client_message(client_id, JSON.stringify({
        "message_type": 1501,
        "message_data": {
            "名称": name,
            "模型": model,
            "对话": text,
            "选项": select,
            "下一页": next_page,
            "剧情": plot,
            "标识数据": flag_data,
        }
    }));
}

/**
 * 向角色客户端发送最后对话框
 */
export function send_characters_client_dialogue(characters_id, model, name, text, select, next_page, plot, flag_data) {
    let client_id = G.Characters.get_characters_client_id(characters_id);
    if (client_id !== undefined) {
        send_client_dialogue(client_id, model, name, text, select, next_page, plot, flag_data);
    }
}

/**
 * 向队友同步对话信息
 * @param {*} dialogue_data 
 */
export function send_team_dialogue_data(login_characters, dialogue_data, fag_data) {
    if (send_team_npc.includes(dialogue_data[1]) && login_characters["队伍"] !== 0 && login_characters["队长"]) {
        let team_data = G.TeamUtils.get_team_data(login_characters["队伍"]);
        if (team_data !== undefined) {
            for (let index = 0; index < team_data["成员"].length; index++) {
                let team_characters_id = team_data["成员"][index];
                //只操作队员
                if (team_characters_id !== login_characters["id"]) {
                    //给队员发送对话框
                    let team_characters = _CharactersData.get(team_characters_id);
                    ClientUtils.send_characters_client_dialogue(team_characters_id, dialogue_data[0], dialogue_data[1], dialogue_data[2], dialogue_data[3], dialogue_data[4], team_characters["剧情"], fag_data);
                    _LastDialogueData.set(login_characters["id"], { "模型": dialogue_data[0], "名称": dialogue_data[1] });
                }
            }
        }
    }
}